package jp.sinmetal.trainer.action.admin;



import javax.annotation.Resource;

import org.apache.struts.action.ActionMessages;
import org.seasar.framework.beans.util.Beans;
import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import java.util.List;

import org.seasar.extension.jdbc.JdbcManager;
import org.seasar.extension.jdbc.where.SimpleWhere;

import jp.sinmetal.trainer.entity.EggGroup;
import jp.sinmetal.trainer.form.EggGroupForm;
import jp.sinmetal.trainer.service.EggGroupService;

public class EggGroupAction {


    public List<EggGroup> eggGroupItems;
    
    @ActionForm
    @Resource
    protected EggGroupForm eggGroupForm;

    @Resource
    protected EggGroupService eggGroupService;

    public JdbcManager jdbcManager;

    @Execute(validator = false)
    public String index() {
        eggGroupItems = eggGroupService.findAll();

        return "list.jsp";
    }





    @Execute(validator = false, urlPattern = "show/{eggGroupId}")
    public String show() {
        EggGroup entity = eggGroupService.findById(Integer.valueOf(eggGroupForm.eggGroupId));
        Beans.copy(entity, eggGroupForm).dateConverter("yyyy-MM-dd").execute();
        return "show.jsp";
    }

    @Execute(validator = false, urlPattern = "edit/{eggGroupId}")
    public String edit() {
        EggGroup entity = eggGroupService.findById(Integer.valueOf(eggGroupForm.eggGroupId));
        Beans.copy(entity, eggGroupForm).dateConverter("yyyy-MM-dd").execute();
        return "edit.jsp";
    }

    @Execute(validator = false)
    public String create() {
        return "create.jsp";
    }

    @Execute(validator = false, urlPattern = "delete/{eggGroupId}/{version}", redirect = true)
    public String delete() {
        EggGroup entity = Beans.createAndCopy(EggGroup.class, eggGroupForm).dateConverter("yyyy-MM-dd").execute();
        eggGroupService.delete(entity);
        return "/eggGroup/";
    }

    @Execute(input = "create.jsp", redirect = true)
    public String insert() {
        EggGroup entity = Beans.createAndCopy(EggGroup.class, eggGroupForm).dateConverter("yyyy-MM-dd").execute();
        eggGroupService.insert(entity);
        return "/eggGroup/";
    }

    @Execute(input = "edit.jsp", redirect = true)
    public String update() {
        EggGroup entity = Beans.createAndCopy(EggGroup.class, eggGroupForm).dateConverter("yyyy-MM-dd").execute();
        eggGroupService.update(entity);
        return "/eggGroup/";
    }
}